from fastapi import FastAPI, Request,Depends
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import os
from starlette.middleware.sessions import SessionMiddleware

from api import ppt as ppt_router
from api import auth as auth_router

app = FastAPI()

# 挂载静态文件路径
app.mount("/static", StaticFiles(directory="static"), name="static")
app.mount("/files", StaticFiles(directory="files"), name="files")

# 设置模板目录
templates = Jinja2Templates(directory="templates")

# 包含API路由
app.include_router(ppt_router.router)
# app.include_router(auth_router)

#Session密钥
SECRET_KEY = os.getenv("SECRET_KEY","")
# 将SessionMiddleware添加到应用中
app.add_middleware(SessionMiddleware, secret_key=SECRET_KEY)

@app.get("/")
async def get_home_page(request: Request):
    return templates.TemplateResponse("ppt.html", {"request": request})

# @app.get("/")
# async def get_home_page(request: Request, user: str = Depends(get_current_user)):
#     return templates.TemplateResponse("index.html", {"request": request,"user": user})

# 运行应用
if __name__ == "__main__":
    import uvicorn
    uvicorn.run(
        "main:app",
        port=9000,
        reload=False,  # 关闭热重载
        workers=1,  # 启用4个工作进程
        limit_concurrency=1000,  # 每个进程最大并发连接数为1000
        log_level="info",  # 设置日志级别为信息
    )
